package cn.tm.ms.nerver.common.forkjoin;

import java.util.Random;
import java.util.concurrent.ForkJoinPool;

public class ForkJoinTaskFactory {
	
	// submit the task to the pool
	final ForkJoinPool pool;
	final ForkJoinTask finder;
	
	public ForkJoinTaskFactory(int parallelism) {
		pool = new ForkJoinPool(parallelism);
		finder = new ForkJoinTask(null);
	}
	
	public void name() {
		
	}
	
	public static void main(String[] args) {
		// create a random data set
		final int[] data = new int[1000];
		final Random random = new Random();
		for (int i = 0; i < data.length; i++) {
			data[i] = random.nextInt(1000000);
		}

		// submit the task to the pool
		final ForkJoinPool pool = new ForkJoinPool(4);
		final ForkJoinTask finder = new ForkJoinTask(data);
		System.out.println(pool.invoke(finder));
	}
}
